﻿using System;

namespace ShapeExer {
    internal class Program
    {
        static void Main(string[] args)
        {
            IShape shape = null;
            Console.WriteLine("请输入你想产生的形状:0(矩形),1(正方形),2(三角形)");
            int n = int.Parse(Console.ReadLine());
            shape = Factory.GetShape(n);
            Console.WriteLine("该形状的面积为："+shape.Area);
            if (shape.isArealegal())
            {
                Console.WriteLine("该形状的面积合法");
            }
            else
            {
                Console.WriteLine("该形状的面积不合法");
            }
            Console.WriteLine("接下来随机产生10个形状对象，并计算这些对象的面积之和");
            Random rd = new Random();
            double sum = 0;//计算面积总和
            for(int i = 1; i <= 10; i++)
            {
                int temp = rd.Next(0, 3);//随机生成0到2的随机数
                shape = Factory.GetShape(temp);
                while (!shape.isArealegal())
                {
                    Console.WriteLine("面积不合法，重新生成一个新的形状对象！");
                    temp = rd.Next(0, 3);//随机生成0到2的随机数
                    shape = Factory.GetShape(temp);
                }
                Console.WriteLine("当前已生成第" + i + "个形状对象");
                sum += shape.Area;
            }
            Console.WriteLine("面积总和为："+sum);
        }
    }
}


